package com.example.smart_campus.controller;


import com.example.smart_campus.common.Res;
import com.example.smart_campus.pojo.dto.students.StudentQuery;
import com.example.smart_campus.pojo.dto.students.StudentUpdate;
import com.example.smart_campus.pojo.dto.students.StudentsTable;
import com.example.smart_campus.pojo.entity.Students;
import com.example.smart_campus.service.StudentsService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 学生表，存储学生的基本信息 前端控制器
 * </p>
 *
 * @author liyv
 * @since 2024-10-19
 */
@RestController
@RequestMapping("/students")
public class StudentsController {

    @Autowired
    StudentsService studentsService ;

    /**
     * 查询所有学生
     * @return 学生list
     */
    @GetMapping("/gets")
    public Res<List<Students>> getsAll() {
        return studentsService.getAllStudents();
    }

    /**
     * 学号/姓名模糊查询
     * @param query string
     * @return student_list
     */
    @PostMapping("/gets/search")
    public Res<List<Students>> getBySearch(@RequestBody @Valid StudentQuery query) {
        return studentsService.getByQuery(query) ;
    }

    /**
     * 批量导入
     * @param tableList 学生信息表格数据
     * @return res
     */
    @PostMapping("/import")
    public Res importByEList(@RequestBody @Valid List<StudentsTable> tableList){
        return studentsService.importByEList(tableList) ;
    }

    /**
     * 按id删除学生
     * @param sid 学生id
     * @return res
     */
    @DeleteMapping("/del/{sid}")
    public Res delById(@PathVariable String sid) {
        return studentsService.delById(sid) ;
    }

    @PutMapping("/update")
    public Res updateStudent(@RequestBody @Valid StudentUpdate update) {
        return studentsService.updateStudent(update) ;
    }
}

